<?php
require_once('lanceur_spip.php'); // SPIP autoload
include_spip('functions/pdk_common');
//require_once(_DIR_PLUGIN_PDK.'classes/forms/PdkFieldsContainer.php');

class testClasspdkFieldsContainer extends SpipTest {
    /**
     * PdkFieldsContainer
     */
    private $f_cont;
    
    /**
     *  Some operations before all tests
     */
	function __construct() {
        //$this->f_cont = new PdkFieldsContainer();
        $this->f_cont = pdk_load_class('PdkFieldsContainer', 'classes/forms/');
    }
    
    /**
     *  Run before each test
     */
    function setUp() {
        
    }
    
    /**
     *  Run after each test
     */
    function tearDown() {
        
    }
    
    /**
     *  Some operations after all tests
     */
	function __destruct() {
        
    }
    
    function testAddField_GetFields() {        
        $fields_check = array("name"=>"Вася", "phone"=>"0937284561");
        //session_set('PdkFieldsContainer_fields');
        
        $this->f_cont->AddField('name', 'Вася');
        $this->f_cont->AddField('phone', '0937284561');
        $fields = $this->f_cont->GetFields();
         
        $this->assertEqual($fields_check, $fields);
    }
    
    function testClearFields() {        
        $this->f_cont->AddField('name', 'Вася');
        $this->f_cont->AddField('phone', '0937284561');
        $this->f_cont->ClearFields();
        $fields = $this->f_cont->GetFields();
        $this->assertEqual(null, $fields);
    }
    
    function testFormNameLetUsUseClassForDifferentFormsConcurently() {
        $fields_check1 = array("name"=>"Вася", "phone"=>"0937284561");
        $fields_check2 = array("name2"=>"Петя", "phone2"=>"06712345216");
        
        $f_cont1 = new PdkFieldsContainer('form1');
        $f_cont2 = new PdkFieldsContainer('form2');
                
        $f_cont1->AddField('name', 'Вася');
        $f_cont2->AddField('name2', 'Петя');
        $f_cont1->AddField('phone', '0937284561');
        $f_cont2->AddField('phone2', '06712345216');
        
        $fields1 = $f_cont1->GetFields();
        $fields2 = $f_cont2->GetFields();
        
        $this->assertEqual($fields_check1, $fields1);    
        $this->assertEqual($fields_check2, $fields2);
    }
}